import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class NewThread {
    public static void main(String[] args) {
        NumberThread numberThread = new NumberThread();
        FutureTask futureTask = new FutureTask(numberThread);
        Thread thread = new Thread(futureTask);
        thread.start();
//        new Thread(futureTask).start();
        try {
            //get返回值即为futureTask构造器参数Callable实现类重写的call的返回值
            Object sum = futureTask.get();
            System.out.println("总和为"+sum);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}
class NumberThread implements Callable{

    @Override
    public Object call() throws Exception {
        int sum = 0;
        for (int i = 1; i <=100; i++) {
            if (i%2==0){
                System.out.println(i);
                sum+=i;
            }

        }
        return sum;
    }
}